package com.zz.common.api

import cats.effect.{Effect, IO}
import com.zz.dsp.idl.DspEvent
import com.zz.common.kafka.KafkaPipeline
import org.http4s.HttpRoutes
import scala.util.Random

import com.zz.common.GlobalContext

/**
  * @author huanggh
  *         19-8-23 上午11:33
  */

class KafkaProduceApi[F[_]](implicit val ef: Effect[F], etx: GlobalContext[IO]) extends SimpleJsonApi[F] {

  override def publicR: HttpRoutes[F] = produceR

  val random: Random.type = scala.util.Random

  val produceR: HttpRoutes[F] = HttpRoutes.of[F] {
    case GET -> Root / "api" / "v0" / "mapping" /"event" =>

      val event = DspEvent(
        imei = random.between(860000000, 869999999).toString
        , imeiMd5 = random.between(860000000, 869999999).toString
        , imeiSha1 = random.between(860000000, 869999999).toString
        , imsi = random.between(15, 16).toString
        , imsiMd5 = "7777777777"
        , imsiSha1 = "6666666666"
        , androidId = "hdshgahl"
        , androidIdMd5 = "5555555555"
        , androidIdSha1 = "44444444444"
        , mac = "slhglsaklglsa;"
        , macMd5 = "33333333333"
        , macSha1 = "22222222222"
        , idfa = "gkldsghlkdl"
        , idfv = "1111111111"
        , mid = random.between(860000000, 869999999).toString
      )
      val _ = KafkaPipeline().toKafka(event)
      Ok("Ok")
  }


}
